﻿using Sx.Mall.Web.Filter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Sx.Mall.Web.Data
{
    /// <summary>
    /// SendMail 的摘要说明
    /// </summary>
    public class ToSendMail : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
         {
            context.Response.ContentType = "text/plain";
            HttpRequest request = context.Request;

            if (request["Type"] == "SendMail")
            {
                string mail = request["mail"];
                SendMail sm = new SendMail();
                string tomail = mail.Trim();
                string title = "新用户注册";
                Random rd = new Random();

                string s = string.Empty;
                for (int i = 0; i < 6; i++)
                {
                    s += rd.Next(1, 9).ToString();
                }

                if (s != string.Empty)
                {
                    string content = "您好！此次注册的验证码为：" + s + "<br/>  感觉您的关注，您的满意是我们毕生的追求";

                    if (sm.Send(sm.MakeMail(tomail, title, content)))
                    {
                        context.Response.Write("<script>alert('验证码发送成功！请注意查收邮件！');<script/>");
                    }
                    else
                    {
                        context.Response.Write("<script>alert('验证码发送失败');<script/>" );
                    }
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}